<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Unit_model extends CI_Model {

	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
		$this->load->database();
	}

	function show_all_unit(){
		$this->load->database();
		$this->db->order_by("id", "desc");
		$query=$this->db->get('tbl_unit');
		if ($query->num_rows() > 0)
		{
			return $query->result();
		}
		return $query->result();
	}
	 
	function load_details($id){
		$this->load->database();
		$this->db->where("id",$id);
		$query=$this->db->get('tbl_unit');
		if ($query->num_rows() > 0)
		{
			return $query->result();
		}
		return $query->result();
	}
	
	function add_units($unit_name){
		$this->load->database();
		$data = array(
				'name_unit'=>$unit_name, 
		);
		$this->db->insert('tbl_unit', $data);
	}
	
	function del_units($id){
		$this->load->database();
		$this->db->where(array(
				'id'=>$id
				 
		));
		$this->db->delete('tbl_unit');
	}
	
	function edit_unit($id,$unit_name){
		$data = array(
				'name_unit'=>$unit_name, 
		);
		$this->db->where('id', $id);
		$this->db->update('tbl_unit', $data);
	}
}
?>